{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4acca4af-be7f-47fa-9597-b77841d1c775",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "4f837fac-9bcf-4a43-a875-1bf3b6f6d649",
   "metadata": {},
   "outputs": [],
   "source": [
    "students = [\n",
    "    {'姓名': '张三', '年龄': 18, '成绩': 85},\n",
    "    {'姓名': '李四', '年龄': 20, '成绩': 72},\n",
    "    {'姓名': '王五', '年龄': 19, '成绩': 90},\n",
    "    {'姓名': '赵六', '年龄': 22, '成绩': 55},\n",
    "    {'姓名': '孙七', '年龄': 21, '成绩': 78},\n",
    "]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "283df72e-d2ac-4869-a749-f152a966902d",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "25e8ceca-3e43-4cd9-b6ec-cc234a13082b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'姓名': '张三', '年龄': 18, '成绩': 85}\n",
      "{'姓名': '李四', '年龄': 20, '成绩': 72}\n",
      "{'姓名': '王五', '年龄': 19, '成绩': 90}\n",
      "{'姓名': '赵六', '年龄': 22, '成绩': 55}\n",
      "{'姓名': '孙七', '年龄': 21, '成绩': 78}\n"
     ]
    }
   ],
   "source": [
    "for s in students:\n",
    "    print(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f68c61a2-b919-4764-81ad-a32e54232d9e",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "f34243e5-4c1d-4d35-9e73-6b4998780e87",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'姓名': '张三', '年龄': 18, '成绩': 85}\n",
      "{'姓名': '李四', '年龄': 20, '成绩': 72}\n",
      "{'姓名': '王五', '年龄': 19, '成绩': 90}\n",
      "{'姓名': '孙七', '年龄': 21, '成绩': 78}\n"
     ]
    }
   ],
   "source": [
    "for s in students:\n",
    "    if s['成绩'] >= 60:\n",
    "        print(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2cf2c7eb-8840-4090-8119-de037e462831",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "ca7e06d5-f2be-43e5-895f-2ff30748c23e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'姓名': '张三', '年龄': 18, '成绩': 85},\n",
       " {'姓名': '李四', '年龄': 20, '成绩': 72},\n",
       " {'姓名': '王五', '年龄': 19, '成绩': 90},\n",
       " {'姓名': '孙七', '年龄': 21, '成绩': 78}]"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "t = []\n",
    "for s in students:\n",
    "    if s['成绩'] >= 60:\n",
    "        t.append(s)\n",
    "t"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c7a5dfba-1023-461a-b95d-bf63138647fa",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "e7c240fd-99f4-4248-84e2-ec720c75d97a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'姓名': '张三', '年龄': 18, '成绩': 85},\n",
       " {'姓名': '李四', '年龄': 20, '成绩': 72},\n",
       " {'姓名': '王五', '年龄': 19, '成绩': 90},\n",
       " {'姓名': '孙七', '年龄': 21, '成绩': 78}]"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[s for s in students if s['成绩'] >= 60]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c1c3b435-3d4b-4a96-ab37-9994fdac3f6e",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "4ae96a29-0986-4fb6-bc07-a273401eca98",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'孙七', '张三', '李四', '王五'}"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "{s['姓名'] for s in students if s['成绩'] >= 60}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ffac49a5-b8ee-49ec-b5c8-ea259a227cd8",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "09999764-f56a-4e3e-98d5-6372c83e2100",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'张三': 85, '李四': 72, '王五': 90, '孙七': 78}"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "{s['姓名']:s['成绩'] for s in students if s['成绩'] >= 60}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "c86d3ff7-5bee-4807-9b29-1ae30b8c04e3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[('张三', 85), ('李四', 72), ('王五', 90), ('孙七', 78)]"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[(s['姓名'], s['成绩']) for s in students if s['成绩'] >= 60]"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
